ShowcaseΒΆ

HoloViews encapsulates your data into storable, composable, sliceable objects, leveraging matplotlib for visualization and IPython Notebook for maximum productivity.

Main features:

  • Preserve your raw data while engaging in rapid, interactive exploratory analysis.
  • Build complex, composite visualizations that are easily interactively customized at any time.
  • Succinct, declarative style allows you to keep all the necessary code visible, enabling your workflow is fully reproducibile.
  • Select, slice, or transform only the relevant data that is currently of interest.
  • Store your raw data as HoloViews objects via pickling, for later analysis or visualization.
  • Strong support for the IPython Notebook, including tab-completion throughout and powerful IPython magics.
  • Seamless (optional) interaction with Pandas Dataframes.

Using IPython notebook is only the first step towards an interactive, exploratory workflow using Python's rich ecosystem of data analysis tools. To make it practical, use HoloViews to greatly improve your productivity, requiring orders of magnitude fewer lines of code and letting you focus on your data itself, not on writing code to visualize and process it.

Here we will show some of the main features of HoloViews, and why it is useful for scientists and engineers.

In [1]:
from holoviews import *
from holoviews.operation import contours, threshold, gradient
import numpy as np

%load_ext holoviews.ipython

For simplicity in this showcase, we use an unqualified import *, but in general we recommend using qualified imports and namespaces (as in from holoviews import Image).

A simple function

First, let us define a mathematical function to explore using the Numpy library:

In [2]:
def sine(x, phase=0, freq=100):
    return np.sin((freq * x + phase))

We will explore the effect of varying phase and frequency:

In [3]:
phases = np.linspace(0,2*np.pi,11)  # Explored phases
freqs = np.linspace(50,150,5)      # Explored frequencies

We will need some spatial sampling too:

In [4]:
dist = np.linspace(-0.5,0.5,202)   # Linear spatial sampling
x,y = np.meshgrid(dist, dist)
grid = (x**2+y**2)                 # Spatial sampling (2D)

Compact data visualization

With HoloViews, we can immediately test our simple function by creating Image and Curve objects to visualize the 2D arrays and 1D cross-sections generated by the sine function, respectively:

In [5]:
freq1 = Image(sine(grid, freq=50))  + Curve(zip(dist, sine(dist**2, freq=50)))
freq2 = Image(sine(grid, freq=200)) + Curve(zip(dist, sine(dist**2, freq=200)))
(freq1 + freq2).cols(2)
Out[5]:

As you can see, Image takes a 2D numpy array as input and Curve accepts a list of (x,y) points. With the + operator we can lay these elements out together and with .cols(2) we can generate a 2 column format.

HoloViews objects like Image and Curve are a great way to work with your data, because they display so easily and flexibly, yet preserve the raw data (the Numpy array in this case) in the .data attribute. Calling matplotlib directly to generate such a figure would take much, much more code, e.g., to label each of the axes, to create a figure with subfigures, etc. Moreover, such code would be focused on the plotting, whereas with HoloViews you can focus directly on what matters: your data, letting it plot itself.

Only two element types are shown above, but HoloViews supports many other types of element that behave in the same way: scatter points, histograms, tables, vectorfields, RGB images, 3D plots, annotations, and many more as shown in the Elements overview. All of these can be combined easily to create even quite complex plots with a minimum of code to write or maintain.

Interactive exploration

We can interactively explore this simple function if we declare the dimensions of the parameter space to be explored (dimensions) as well as the specific samples to take in this parameter space (keys):

In [6]:
dimensions = ['Phase', 'Frequency']
keys = [(p,f) for p in phases for f in freqs]

Now we create a high-dimensional HoloMap to explore: The tuple keys are the points in the parameter space, and the values are the corresponding Image objects:

In [7]:
items = [(k, Image(sine(grid, *k), value_dimensions=['Amplitude'])) for k in keys]
circular_wave = HoloMap(items, key_dimensions=dimensions)
circular_wave
Out[7]:
Phase:

Frequency:

You can still compose as many visualization elements as you wish together. Here is a demonstration of how to generate the horizontal cross-section of the circular wave using Curve elements. This is then positioned next to our circular wave:

In [8]:
items = [(k, Curve(zip(dist, sine(dist**2, *k)))) for k in keys]
sections = HoloMap(items, key_dimensions=dimensions)
circular_wave + sections
Out[8]:
Phase:

Frequency:

You can then easily export your HoloMap objects to an interactive notebook, video formats, or GIF animations for a web page.

Succinct Analysis

HoloViews offers a suite of general operations to analyze your data, generating new HoloView structures in the process. Here we pick a point on the circular wave at (0,0.25) and plot the amplitude value as a function of phase.

The circular wave is shown annotated with a point at the chosen position. Note how we can still interactively explore the remaining dimensions, namely Frequency.

In [9]:
sample_pos = (0,0.25)
annotated = circular_wave * Points([sample_pos])
sample = circular_wave.sample(samples=[sample_pos]).to.curve('Phase', 'Amplitude')
annotated + sample
Out[9]:
Phase:

Frequency:

Note that the spatial frequency of our curve plot is not affected by the frequency of our wave. That is because the phase always spans exactly one cycle at any of the chosen frequencies.

Here is the circular wave annotated with contours at the 0.5 level, followed by a thresholded version of the same wave, and then the gradient of this pattern, along with a histogram of the gradient values:

In [10]:
%%output holomap='gif'
%%opts Image (cmap='gray') Contours (color='r')
m=HoloMap([(p, Image(sine(grid, phase=p))) for p in phases], key_dimensions=['Phase'])
contours(m, levels=[0.5]) + threshold(m, level=0.5) + gradient(m).hist(bin_range=(0,0.7))
Out[10]:

Note that this forms an animation, because the data covers multiple phases; each frame of the animation shows the result from one phase. To get a static plot, just select one phase out of this space instead of a whole list of phases as done here. Supplied operations include gradient, fft_power, convolve, histogram, vectorfield, analyze_roi and many more.

Flexible display system

Remember the initial test of the sine function? Those two composite objects are still in the namespace and even though the objects have already been created, we can still style the display in any way we like. This styling is done separately from specifying your data, so that your data is still clearly listed independently of how it is being viewed:

In [11]:
%%opts Image (cmap='jet') Curve (color='g')
(freq1 + freq2).cols(2)
Out[11]:

Understand your data

HoloViews is designed to make it easy to understand your data. For instance, these two circular waves have two very different amplitudes. HoloViews ensures that these differences are visible by default, by normalizing across the two elements when they are displayed together:

In [12]:
%%opts Image (cmap='gray')
comparison = Image(sine(grid)) + Image(sine(grid, phase=np.pi)*0.02)
comparison
Out[12]:

Unfortunately, although we now have a clear representation of the relative amplitudes, the spatial structure of the low-amplitude wave is hard to see. Fortunately, it is easy to instruct HoloViews to stop normalizing the group if you are more interested in spatial structure than amplitude:

In [13]:
%%opts Image {+axiswise} (cmap='gray')
comparison
Out[13]:

Much much more!

HoloViews supports your workflow from initial exploration to final publication. HoloViews is designed to be agnostic to whatever task or data you happen to be analyzing, allowing you to discover whatever is important for your engineering applications or scientific problems of any sort.

To learn more, check out the other tutorials and notebooks:

  • Introduction: Step-by-step explanation of the basic concepts in HoloViews

  • Exploring Data and Transforming Data: How to use HoloViews to explore heterogenous collections of data, by combining, selecting, or transforming your data of interest.

  • Elements: Overview of all the basic Elements

  • Containers: Overview of all the containers for Elements